package com.itheima.homework.work2;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入您的生日(xxxx-xx-xx):");
        String birthday = sc.nextLine();// "2003-11-11"

        // 把字符串生日转成Date对象
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date d1 = sdf.parse(birthday);
        // 拿到生日到1970/1/1所经历的毫秒值
        long time1 = d1.getTime();

        // 当前系统时间
        Date d2 = new Date();
        // 获取当前系统时间到1970/1/1所经历的毫秒值
        long time2 = d2.getTime();

        if(time2 - time1 > 0){
            System.out.println("活了"+(time2-time1)*1.0/(1000L*60*60*24*365)+"年");
        }else{
            System.out.println("您还没出生!");
        }


    }
}
